<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>BadgerDB: bufmgr/src/buffer.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">BadgerDB
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">bufmgr/src/buffer.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;memory&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;buffer.h&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;exceptions/buffer_exceeded_exception.h&quot;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;exceptions/page_not_pinned_exception.h&quot;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;exceptions/page_pinned_exception.h&quot;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;exceptions/bad_buffer_exception.h&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &quot;exceptions/hash_not_found_exception.h&quot;</span>
<a name="l00016"></a>00016 
<a name="l00017"></a><a class="code" href="namespacebadgerdb.html">00017</a> <span class="keyword">namespace </span>badgerdb { 
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#a18b7cf23b619c7c0e593d1dc45da77b4">00019</a> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a18b7cf23b619c7c0e593d1dc45da77b4">BufMgr::BufMgr</a>(std::uint32_t bufs)
<a name="l00020"></a>00020   : numBufs(bufs) {
<a name="l00021"></a>00021   bufDescTable = <span class="keyword">new</span> <a class="code" href="classbadgerdb_1_1_buf_desc.html" title="Class for maintaining information about buffer pool frames.">BufDesc</a>[bufs];
<a name="l00022"></a>00022 
<a name="l00023"></a>00023   <span class="keywordflow">for</span> (<a class="code" href="namespacebadgerdb.html#a1e7378fbefaea050a47e6cde929e9c01" title="Identifier for a frame in buffer pool.">FrameId</a> i = 0; i &lt; bufs; i++) 
<a name="l00024"></a>00024   {
<a name="l00025"></a>00025     bufDescTable[i].frameNo = i;
<a name="l00026"></a>00026     bufDescTable[i].valid = <span class="keyword">false</span>;
<a name="l00027"></a>00027   }
<a name="l00028"></a>00028 
<a name="l00029"></a>00029   <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa498047fc351652d0bc7eabf6cb62ab0">bufPool</a> = <span class="keyword">new</span> <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>[bufs];
<a name="l00030"></a>00030 
<a name="l00031"></a>00031   <span class="keywordtype">int</span> htsize = ((((int) (bufs * 1.2))*2)/2)+1;
<a name="l00032"></a>00032   hashTable = <span class="keyword">new</span> <a class="code" href="classbadgerdb_1_1_buf_hash_tbl.html" title="Hash table class to keep track of pages in the buffer pool.">BufHashTbl</a> (htsize);  <span class="comment">// allocate the buffer hash table</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034   clockHand = bufs - 1;
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 
<a name="l00038"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#aab08001e1be18bfbd4af9113e91cf953">00038</a> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aab08001e1be18bfbd4af9113e91cf953">BufMgr::~BufMgr</a>() {
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="keywordtype">void</span> BufMgr::advanceClock()
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 
<a name="l00046"></a>00046 <span class="keywordtype">void</span> BufMgr::allocBuf(<a class="code" href="namespacebadgerdb.html#a1e7378fbefaea050a47e6cde929e9c01" title="Identifier for a frame in buffer pool.">FrameId</a> &amp; frame) 
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00050"></a>00050   
<a name="l00051"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#a9f853f0f1d4628e7e14374d0c7c6a4f3">00051</a> <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a9f853f0f1d4628e7e14374d0c7c6a4f3">BufMgr::readPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> pageNo, <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>*&amp; page)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa9bdf04c8543f59744db22efa9420c89">00056</a> <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa9bdf04c8543f59744db22efa9420c89">BufMgr::unPinPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> pageNo, <span class="keyword">const</span> <span class="keywordtype">bool</span> dirty) 
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#acc61d1985720411ebb76e70f702827d3">00060</a> <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#acc61d1985720411ebb76e70f702827d3">BufMgr::flushFile</a>(<span class="keyword">const</span> <a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file) 
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#ab9ae3b12aac55b119b5763e3de2a4d2b">00064</a> <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#ab9ae3b12aac55b119b5763e3de2a4d2b">BufMgr::allocPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> &amp;pageNo, <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>*&amp; page) 
<a name="l00065"></a>00065 {
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067 
<a name="l00068"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#a598b3112b8193af603f5bc97c478a671">00068</a> <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a598b3112b8193af603f5bc97c478a671">BufMgr::printSelf</a>(<span class="keywordtype">void</span>) 
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070   <a class="code" href="classbadgerdb_1_1_buf_desc.html" title="Class for maintaining information about buffer pool frames.">BufDesc</a>* tmpbuf;
<a name="l00071"></a>00071   <span class="keywordtype">int</span> validFrames = 0;
<a name="l00072"></a>00072   
<a name="l00073"></a>00073   <span class="keywordflow">for</span> (std::uint32_t i = 0; i &lt; numBufs; i++)
<a name="l00074"></a>00074   {
<a name="l00075"></a>00075     tmpbuf = &amp;(bufDescTable[i]);
<a name="l00076"></a>00076     std::cout &lt;&lt; <span class="stringliteral">&quot;FrameNo:&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00077"></a>00077     tmpbuf-&gt;Print();
<a name="l00078"></a>00078 
<a name="l00079"></a>00079     <span class="keywordflow">if</span> (tmpbuf-&gt;valid == <span class="keyword">true</span>)
<a name="l00080"></a>00080       validFrames++;
<a name="l00081"></a>00081   }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   std::cout &lt;&lt; <span class="stringliteral">&quot;Total Number of Valid Frames:&quot;</span> &lt;&lt; validFrames &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Wed Jan 30 2013 14:17:48 for BadgerDB by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
